package hlhj.fhp.supreme.activitys

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response
import hlhj.fhp.supreme.BaseAty
import hlhj.fhp.supreme.R
import hlhj.fhp.supreme.javabean.ExtensionDetailBean
import hlhj.fhp.supreme.network.Urls
import hlhj.fhp.supreme.utils.JsonCallBack
import hlhj.fhp.supreme.utils.MyUtils
import kotlinx.android.synthetic.main.activity_my_extension_detail_aty.*
import java.util.ArrayList

class MyExtensionDetailAty : BaseAty() {
    private lateinit var adp :BaseQuickAdapter<ExtensionDetailBean.DataBean.OrderBean,BaseViewHolder>
    private val datas=ArrayList<ExtensionDetailBean.DataBean.OrderBean>()
    override fun getContentId(): Int {
        return R.layout.activity_my_extension_detail_aty
    }
    override fun initListener() {
        btExit.setOnClickListener {
            finish()
        }
    }


    override fun initView() {
        adp=object :BaseQuickAdapter<ExtensionDetailBean.DataBean.OrderBean,BaseViewHolder>(R.layout.extension_detail_item,datas){
            override fun convert(helper: BaseViewHolder?, item: ExtensionDetailBean.DataBean.OrderBean?) {
                helper?.setText(R.id.orderNum,item?.order_sn)
                helper?.setText(R.id.orderPrice,"￥${item?.money}")
                helper?.setText(R.id.moeny,"￥${item?.omoney}")
            }
        }
        listView.adapter=adp
        listView.layoutManager=LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false)
        disPatchData()

    }

    private fun disPatchData() {
        OkGo.post<ExtensionDetailBean>(Urls.BaseUrl + Urls.EXTENSION_DETAIL)
                .params("id", intent.getStringExtra("id"))
                .execute(object : JsonCallBack<ExtensionDetailBean>(this) {
                    override fun onSuccess(response: Response<ExtensionDetailBean>?) {
                        val bean = response?.body()
                        if (bean?.code == 1) {
                            userName.text = bean?.data.user.name
                            userNick.text = bean?.data.user.user_nickname
                            time.text = MyUtils.timeStampToStrYMD(bean?.data.user.create_time.toLong())

                            datas.addAll(bean?.data.order)
                            adp.notifyDataSetChanged()

                        }
                    }
                })
    }

}
